package com.shop2cn.iapi.agentproducts.testcase;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.FastImportProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductListDto;
import com.shop2cn.iapi.agentproducts.service.FastImportProductCall;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.SetMarkupConfigBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.SetMarkupConfigCall;
import com.ymatou.iapi.prodstock.parameter.AgentProductPo;
import com.ymatou.iapi.productquery.parameter.GetProductListBySellerIdBean;
import com.ymatou.iapi.productquery.service.GetProductListBySellerIdCall;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AssertService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.model.YmtProductsI;
import com.ymttest.database.model.stockmgr.agentinventory;
import com.ymttest.database.model.stockmgr.agentinventoryExample;
import com.ymttest.database.model.stockmgr.agentinventorysku;
import com.ymttest.database.model.stockmgr.agentinventoryskuExample;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.database.sqlwapper.stockmgr.agentinventoryWapper;
import com.ymttest.database.sqlwapper.stockmgr.agentinventoryskuWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.YMTDateUtil;

/**
*快速导入商品
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_FastImportProduct{
	private static FastImportProductBean fastimportproductBean;
	private static FastImportProductCall fastimportproductCall;
	private static YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
	private static YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
	
	agentinventoryExample inventoryExample=new agentinventoryExample();
	agentinventoryWapper inventory=new agentinventoryWapper();
	
	agentinventoryskuExample skuExample=new agentinventoryskuExample();
	agentinventoryskuWapper sku=new agentinventoryskuWapper();
	
	//渠道商
	private static int rootUserId = AgentUsers.rootUserId;
	//渠道商->代理商1
	private static int agentUserId1 = AgentUsers.agentUserId1;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("快速导入商品");
	}

	@Before
	public void caseUp() {
		fastimportproductBean=new FastImportProductBean();
		fastimportproductCall=new FastImportProductCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(fastimportproductCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	public void verifyDB(String productId,FastImportProductBean fastimportproductBean) throws InterruptedException {
        AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(productId);
        Logger.verifyEquals(fastimportproductBean.getUserId(),agentProductPo.getUserId(),"验证userId");
        Logger.verifyEquals(0,agentProductPo.getAgentType(),"验证AgentType");
        Logger.verifyEquals(false,agentProductPo.isSetAgentPrice(),"验证SetAgentPrice");
        Logger.verifyEquals(2,agentProductPo.getStatus(),"验证商品是下架状态");
        Logger.verifyEquals(-1,agentProductPo.getInfoProgress(),"验证InfoProgress");
        Logger.verifyEquals(0,agentProductPo.getAction(),"验证Action");
        Logger.verifyEquals(fastimportproductBean.getUserId(),agentProductPo.getRootUserId(),"验证RootUserId");
        Logger.verifyEquals(productId,agentProductPo.getRootProductId(),"验证RootProductId");

        List<YmtProductsI> ymtProductsI = ymtProductsIWapper.selectProductByProductId(productId);
        Logger.verifyEquals(true,ymtProductsI.size()>0,"验证商品表中含有数据");
        Logger.verifyEquals(3,ymtProductsI.get(0).getProductType(),"验证商品类型");
        List<YmtCatalogsI> catalogsIS = ymtCatalogsIWapper.selectCatalogsByProductId(productId);
        Logger.verifyEquals(true,catalogsIS.size()>0,"验证规格表中含有数据");

        List<Map> maps = ymtProductsIWapper.getSellerProductDetailList_ProductPicture(productId);
        maps.forEach(p->{
            Logger.verifyEquals(true,fastimportproductBean.getProductPicList().contains(p.get("PicUrl").toString()),"验证商品图片");
        });
        List<YmtCatalogsI> ymtCatalogsIList = ymtCatalogsIWapper.selectCatalogsByProductId(productId);
        IntergratedProductMapper ipm = SqlMapperFactory
                .getIntergratedProductMapper();
        fastimportproductBean.getCatalogList().forEach(p-> {
            for (YmtCatalogsI ymtCatalogsI : ymtCatalogsIList
            ) {
                //check Ymt_CatalogSetAttributes
                Map<String, Object> map = ipm.selectCatalogProAndValByCatalogId(ymtCatalogsI.getsCatalogId()).get(0);
                if (map.get("sCategoryAttribute").equals(p.getPropertyValue())) {
                    Logger.verifyEquals(productId, map.get("sProductId").toString(), "验证Ymt_CatalogSetAttributes表");
                    Logger.comment("验证规格");
                    Logger.verifyEquals(p.getDirectPrice(), ymtCatalogsI.getfQuotePrice().doubleValue(), "验证直销价");
                    Logger.verifyEquals(p.getStock(), ymtCatalogsI.getiNum(), "验证库存");
                    Logger.verifyEquals(0, ymtCatalogsI.getiAction(), "验证action");
                    Logger.verifyEquals(p.getSku(), ymtCatalogsI.getsSKU(), "验证sku");
                    Logger.verifyEquals(p.getWeight(), ymtCatalogsI.getWeight().doubleValue(), "验证Weight");
                    AssertService.assertTime(YMTDateUtil.getDate(), (Date) ymtCatalogsI.getdAddTime(), 120, "验证商品规格的发布时间");
                }
            }
        });
    }

	public void verifyMongoCurMq(String pid) throws IOException, InterruptedException {
        Thread.sleep(5000);
        MessageListBean MessageListBean2 = MqQueryCallService.initAgentMongoCrud(pid);
        List<Map> joa2 = MqQueryCallService.GetMqMessage(MessageListBean2);
        Logger.debug(joa2);
        String actionType = "AddAgentProduct";
        String appId = "agentproducts.iapi.ymatou.com";
        Logger.verifyEquals(actionType,joa2.get(0).get("ActionType"),"验证ActionType");
        Logger.verifyEquals(pid,joa2.get(0).get("ProductId"),"验证ProductId");
        Logger.verifyEquals(appId,joa2.get(0).get("AppId"),"验证AppId");

    }
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_FastImportProduct_01() {
		Logger.start(true,"渠道商快速导入商品,导入成功");
		try {
			Logger.comment("入库前的数量");
			inventoryExample.createCriteria().andSellerIdEqualTo(rootUserId);	
			List<agentinventory> inventorys1=inventory.selectByExample(inventoryExample);
			
			fastimportproductBean = AddAgentProductCallService.initFastImportProductBean(rootUserId);
			fastimportproductCall.setData(fastimportproductBean);
			fastimportproductCall.callService();
            Logger.verifyEquals("200",fastimportproductCall.getString("code"),"验证code");
            String productId = fastimportproductCall.getString("data");
            verifyDB(productId,fastimportproductBean);
            verifyMongoCurMq(productId);

            //新增验证 wuwen 20200214
			inventoryExample.createCriteria().andSellerIdEqualTo(rootUserId);
			inventoryExample.setOrderByClause(" id desc ");
			skuExample.createCriteria().andProductIdEqualTo(productId);
			List<agentinventorysku> skus=sku.selectByExample(skuExample);
			Logger.comment("入库后的数量");
			List<agentinventory> inventorys2=inventory.selectByExample(inventoryExample);
			Logger.verifyEquals(2, skus.size(), "验证agentinventorysku中新增一条数据");
			Logger.verifyEquals(1, inventorys2.size()-inventorys1.size(), "验证agentinventory中新增一条数据");
			
			agentinventory inventory=inventorys2.get(0); 
			Logger.verifyEquals(100,skus.get(0).getNum(), "验证agentinventorysku中的第一个规格库存");
			Logger.verifyEquals(100,skus.get(1).getNum(), "验证agentinventorysku中的第二个规格库存");
			
			Logger.verifyEquals(4,inventory.getType(), "验证agentinventorysku中的type=4");
			Logger.verifyNotNull(inventory.getInventoryNo(), "验证agentinventory中的InventoryNo单号");
			
			
        } catch (Exception e) {
			Logger.fail(e);
		}
	}

    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_04() {
        Logger.start(true,"渠道商快速导入商品，商品名称为空,导入失败");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBean(rootUserId);
            fastimportproductBean.setProductName(null);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("400",fastimportproductCall.getString("code"),"验证code");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_05() {
        Logger.start(true,"渠道商快速导入商品，商品图片为空，导入失败");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBean(rootUserId);
            fastimportproductBean.setProductPicList(null);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("400",fastimportproductCall.getString("code"),"验证code");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }


    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_02() {
        Logger.start(true,"代理商快速导入商品，导入失败");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBean(agentUserId1);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("201",fastimportproductCall.getString("code"),"验证code");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_03() {
        Logger.start(true,"userId为空，导入失败");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBean(0);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("400",fastimportproductCall.getString("code"),"验证code");
//            Logger.verifyEquals("无效的商户编号",fastimportproductCall.getString("message"),"验证message");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_06() {
        Logger.start(true,"商品图片大于9张，导入失败");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBean(rootUserId);
            List<String> picList = new ArrayList<>();
            for(int i=0;i<10;i++){
                picList.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
            }
            fastimportproductBean.setProductPicList(picList);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("400",fastimportproductCall.getString("code"),"验证code");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }


    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_08() {
        Logger.start(true,"商品名称为空，导入失败");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBean(rootUserId);
            String title = null;
            fastimportproductBean.setProductName(title);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("400",fastimportproductCall.getString("code"),"验证code");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    
    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_09() {
        Logger.start(true,"详情图片超过30张，导入失败");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBean(rootUserId);
            List<String> picList = new ArrayList<>();
            for (int i = 0;i<31;i++){
                picList.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
            }
            fastimportproductBean.setDescPicList(picList);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("400",fastimportproductCall.getString("code"),"验证code");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_10() {
        Logger.start(true,"详情文字超过700个字符，导入失败");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBean(rootUserId);
            String s = "1";
            for (int i = 0;i<701;i++){
                s = s+1;
            }
            fastimportproductBean.setDescription(s);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("400",fastimportproductCall.getString("code"),"验证code");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }
    
    
    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_12() {
        Logger.start(true,"三级分类不正确，失败");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBeanV2(rootUserId);
            fastimportproductBean.setThirdCategoryId(300000);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("201",fastimportproductCall.getString("code"),"验证code");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }
    
    
    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_13() {
        Logger.start(true,"品牌id不正确，失败");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBeanV2(rootUserId);
            fastimportproductBean.setBrandId(99999);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("201",fastimportproductCall.getString("code"),"验证code");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }
    
    
    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_14() {
        Logger.start(true,"物流方式错误，失败");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBeanV2(rootUserId);
            fastimportproductBean.setCatalogStatus(2);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("200",fastimportproductCall.getString("code"),"验证code");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }
    
    
    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_15() {
        Logger.start(true,"物流方式中身份信息提供方式不正确，失败");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBeanV2(rootUserId);
            fastimportproductBean.setCardInfo(666);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("400",fastimportproductCall.getString("code"),"验证code");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }
    
    
    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_16() {
        Logger.start(true,"税率不正确，失败");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBeanV2(rootUserId);
            fastimportproductBean.setTariffRate(3);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("400",fastimportproductCall.getString("code"),"验证code");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }
   
    

    
    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_17() {
        Logger.start(true,"信息填写正确，成功");
        try {
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBeanV2(rootUserId);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("200",fastimportproductCall.getString("code"),"验证code");
            String vipAgentUserId1 = fastimportproductCall.getJsonObject().get("data").getAsString();
            
            Thread.sleep(5000);
            
            String newProductId = fastimportproductCall.getJsonObject().get("data").getAsString();
            GetProductListBySellerIdCall gbc=new GetProductListBySellerIdCall();
			GetProductListBySellerIdBean b=new GetProductListBySellerIdBean();
			b.setPageIndex(1);
			b.setPageSize(50);
			b.setSellerId(rootUserId);
			b.setProductType(0);
			gbc.setData(b);
			gbc.callService();
            
            
//          GetProductInfoByProductIdCall gbc=new GetProductInfoByProductIdCall();
//			GetProductInfoByProductIdBean b=new GetProductInfoByProductIdBean();
//			b.setProductId(newProductId);
//			gbc.setData(b);
//			gbc.callService();
        } catch (Exception e) {
            Logger.fail(e);
        }
    }
    
    
    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FastImportProduct_18() {
        Logger.start(true,"渠道商导入一个价格超出范围的商品，导入失败");
        try {
        	int vipRootUserId= GodmchManageCallService.CreateSellerMch();
            fastimportproductBean = AddAgentProductCallService.initFastImportProductBeanV2(vipRootUserId);
            fastimportproductBean.getCatalogList().get(0).setDirectPrice(10001.00);
            fastimportproductCall.setData(fastimportproductBean);
            fastimportproductCall.callService();
            Logger.verifyEquals("400",fastimportproductCall.getString("code"),"验证code");
            Logger.verifyIsContains("单价超过限额",fastimportproductCall.getString("message"),"验证message");
            
        } catch (Exception e) {
            Logger.fail(e);
        }
    }
    
    
    @Test
	@Category({ P1.class })
	@TestCase
	public void Tc_FastImportProduct_19() {
		Logger.start(true, "自动导入的时候，勾选自动上架--会mq回调自动导入，然后验证价格，验证打标");
		try {

			// 创建渠道商
			CreateCodeBean createAllMsgSellerMch = GodmchManageCallService.CreateAllMsgSellerMch();
			// 创建渠道商邀请码
			CreateCodeCall createCodeCall2 = GodmchManageCallService.createCodeCall(createAllMsgSellerMch);
			// 创建代理商
			Integer agentUserId = GodmchManageCallService.CreateSellerMch(
					createCodeCall2.getJsonObject().getAsJsonObject("result").get("code").getAsString());
			int rootUserId = createAllMsgSellerMch.getMchId();

			SetMarkupConfigBean bean = GodmchManageCallService.initSetMarketupBean(agentUserId,
					Arrays.asList(rootUserId));
			SetMarkupConfigCall call = GodmchManageCallService.SetMarketupBeanCall(bean);

			fastimportproductBean = AddAgentProductCallService.initFastImportProductBeanV2(rootUserId);
			fastimportproductBean.setTariffRate(0);
	        fastimportproductCall.setData(fastimportproductBean);
	        fastimportproductCall.callService();
			
			Logger.verifyEquals("200", fastimportproductCall.getString("code"), "验证Code");
			String productId = fastimportproductCall.getJsonObject().get("data").getAsString();
			
			//验证mq
			MessageListBean MessageListBean = MqQueryCallService.initImportAgentproduct(productId, rootUserId);
            List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
            if(joa.size()==0){
                    Thread.sleep(5000);
                     joa = MqQueryCallService.GetMqMessage(MessageListBean);
            }
            joa.forEach(ele->{
                    Logger.debug(ele.toString());
            });
            
            //验证价格
            List<ProductListDto> getProductLists2 = AddAgentProductCallService.GetProductLists(agentUserId);
			ProductListDto agentProd = getProductLists2.get(0);
			double agentprice = agentProd.getCatalogList().get(0).getAgentPrice();
			// 代理价*1.33=直销价
			Logger.verifyEquals(new Long(Math.round(agentprice * 1.33)).intValue(),
					new Double(agentProd.getCatalogList().get(0).getDirectPrice()).intValue(), "");
			
			//商品打标
			Logger.verifyEquals(agentProd.getAutoMarkupStatus(),1,"已经被打上自动加价的标");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_FastImportProduct_20() {
		Logger.start(true, "自动导入的时候，没有勾选自动上架--mq不会去回调自动导入");
		try {

			// 创建渠道商
			CreateCodeBean createAllMsgSellerMch = GodmchManageCallService.CreateAllMsgSellerMch();
			// 创建渠道商邀请码
			CreateCodeCall createCodeCall2 = GodmchManageCallService.createCodeCall(createAllMsgSellerMch);
			// 创建代理商
			Integer agentUserId = GodmchManageCallService.CreateSellerMch(
					createCodeCall2.getJsonObject().getAsJsonObject("result").get("code").getAsString());
			int rootUserId = createAllMsgSellerMch.getMchId();

			SetMarkupConfigBean bean = GodmchManageCallService.initSetMarketupBean(agentUserId,
					Arrays.asList(rootUserId));
			bean.setOnSaleType(2);
			SetMarkupConfigCall call = GodmchManageCallService.SetMarketupBeanCall(bean);

			fastimportproductBean = AddAgentProductCallService.initFastImportProductBeanV2(rootUserId);
	        fastimportproductCall.setData(fastimportproductBean);
	        fastimportproductCall.callService();
			
			Logger.verifyEquals("200", fastimportproductCall.getString("code"), "验证Code");
			String productId = fastimportproductCall.getJsonObject().get("data").getAsString();
			
			//验证mq
			MessageListBean MessageListBean = MqQueryCallService.initImportAgentproduct(productId, rootUserId);
            List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
            if(joa.size()==0){
                    Thread.sleep(5000);
                     joa = MqQueryCallService.GetMqMessage(MessageListBean);
            }
            
            Logger.verifyEquals(joa.size(), 0, "没有回调总线消息");
            //验证价格
            List<ProductListDto> getProductLists2 = AddAgentProductCallService.GetProductLists(agentUserId);
			Logger.verifyEquals(getProductLists2.size(),0,"没有自动导入");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	 @Test
		@Category({ P1.class })
		@TestCase
		public void Tc_FastImportProduct_22() {
			Logger.start(true, "多级VIP代理在 自动导入的时候，勾选自动上架--会mq回调自动导入，然后验证价格，验证打标");
			try {

				int vipRootUserId=500781768;
				int vipAgentUserId=500781769;
				int vipAgentUserId1=500781770;

				fastimportproductBean = AddAgentProductCallService.initFastImportProductBeanV2(vipRootUserId);
				fastimportproductBean.setTariffRate(0);
		        fastimportproductCall.setData(fastimportproductBean);
		        fastimportproductCall.callService();
				Logger.verifyEquals("200", fastimportproductCall.getString("code"), "验证Code");
				String productId = fastimportproductCall.getJsonObject().get("data").getAsString();
				AddAgentProductCallService.SetOnshelf(productId, vipRootUserId);
				
				//验证以及代理 mq
				MessageListBean MessageListBean = MqQueryCallService.initImportAgentproduct(productId, vipAgentUserId);
	            List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
	            if(joa.size()==0){
	                    Thread.sleep(5000);
	                     joa = MqQueryCallService.GetMqMessage(MessageListBean);
	            }
	            joa.forEach(ele->{
	                    Logger.debug(ele.toString());
	            });
	            Logger.verifyEquals(joa.size(), 1, "验证消息总线"+MessageListBean.toString());
	            
	            //验证价格
	            List<ProductListDto> getProductLists2 = AddAgentProductCallService.GetProductLists(vipAgentUserId);
				ProductListDto agentProd = getProductLists2.get(0);
				double agentprice = agentProd.getCatalogList().get(0).getAgentPrice();
				// 代理价*1.33=直销价
				Logger.verifyEquals(new Long(Math.round(agentprice * 1.1)).intValue(),
						new Double(agentProd.getCatalogList().get(0).getDirectPrice()).intValue(), "验证一级代理价格");
				
				//商品打标
				Logger.verifyEquals(agentProd.getAutoMarkupStatus(),1,"已经被打上自动加价的标");
				
				
				//验二级及代理 mq
				MessageListBean MessageListBean1 = MqQueryCallService.initImportAgentproduct(agentProd.getProductId(), vipAgentUserId1);
	            List <Map> joa1 = MqQueryCallService.GetMqMessage(MessageListBean);
	            if(joa1.size()==0){
	                    Thread.sleep(5000);
	                     joa1 = MqQueryCallService.GetMqMessage(MessageListBean);
	            }
	            joa1.forEach(ele->{
	                    Logger.debug(ele.toString());
	            });
	            Logger.verifyEquals(joa1.size(), 1, "验证消息总线"+MessageListBean.toString());
	            
	            //验证价格
	            List<ProductListDto> getProductLists21 = AddAgentProductCallService.GetProductLists(vipAgentUserId1);
				ProductListDto agentProd1 = getProductLists21.get(0);
				double agentprice1 = agentProd1.getCatalogList().get(0).getAgentPrice();
				// 代理价*1.33=直销价
				Logger.verifyEquals(new Long(Math.round(agentprice1 * 1.1)).intValue(),
						new Double(agentProd1.getCatalogList().get(0).getDirectPrice()).intValue(), "验证二级代理价格");
				
				//商品打标
				Logger.verifyEquals(agentProd1.getAutoMarkupStatus(),1,"已经被打上自动加价的标");
				
			} catch (Exception e) {
				Logger.fail(e);
			}
		}

     
}